
<?php require 'hrfuns.php'; ?>
<?php
function dump_table($iSQL, $table)
{
    echo "# Dump data for $table\n";
    
    $sqlstr = "select * from $table order by 1";
    if ($result = $iSQL->query($sqlstr)) {

        while($row = $result->fetch_row()) {

            for($i = 0; $i < $result->field_count; $i++) {
                if ($i != 0) echo ", ";
                echo $row[$i];
            }
            echo "\n";
        }

        $result->close();
    }    
}

Valid_Client();
if (isset($_POST["submit"])) {

    $table = $_POST['selTableName'];
    $iSQL = GetSQL();

    header("Content-type:text/plan");
    header("Content-Disposition:attachment;filename=$table.csv");

    dump_table($iSQL, $table);

    $iSQL->close();
}
?>

